home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 January / macpower199701.bin / AMUG / Programming_10 / Videotoolbox 96-08-22-c.sit / VideoToolbox / VideoToolboxSources / HexToBinary.c < prev    next >
MacBinary  |  1995-06-17  |  2.6 KB  |  [TEXT/CWIE]

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: MacBinary (archive/macBinary).

You can browse this item here: HexToBinary.c

ConfidenceProgramDetectionMatch TypeSupport
66% dexvert Compact Compressed (Unix) (archive/compact) ext Supported
10% dexvert MacBinary (archive/macBinary) fallback Supported
1% dexvert Text File (text/txt) fallback Supported
100% file MacBinary II, inited, Sat Jun 17 01:06:08 1995, modified Sat Jun 17 01:06:08 1995, creator 'CWIE', type ASCII, 1945 bytes "HexToBinary.c" , at 0x819 410 bytes resource default (weak)
99% file data default
74% TrID Macintosh plain text (MacBinary) default
25% TrID MacBinary 2 default (weak)
100% siegfried fmt/1762 MacBinary (II) default
100% lsar MacBinary default


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[CWIE]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 0d 48 65 78 54 6f 42 | 69 6e 61 72 79 2e 63 00 |..HexToB|inary.c.|
|00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 54 45 58 54 43 57 49 | 45 01 00 00 00 00 00 00 |.TEXTCWI|E.......|
|00000050| 00 00 00 00 00 07 99 00 | 00 01 9a ac 08 13 40 ac |........|......@.|
|00000060| 08 13 40 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |..@.....|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 9a 72 00 00 |........|.....r..|
|00000080| 2f 2a 0d 48 65 78 54 6f | 42 69 6e 61 72 79 2e 63 |/*.HexTo|Binary.c|
|00000090| 0d 54 77 6f 20 72 6f 75 | 74 69 6e 65 73 20 74 68 |.Two rou|tines th|
|000000a0| 61 74 20 74 72 61 6e 73 | 6c 61 74 65 20 62 61 63 |at trans|late bac|
|000000b0| 6b 20 61 6e 64 20 66 6f | 72 74 68 20 62 65 74 77 |k and fo|rth betw|
|000000c0| 65 65 6e 20 61 20 62 69 | 6e 61 72 79 20 6f 62 6a |een a bi|nary obj|
|000000d0| 65 63 74 20 28 73 6f 6d | 65 20 6e 75 6d 62 65 72 |ect (som|e number|
|000000e0| 0d 6f 66 20 62 79 74 65 | 73 20 61 74 20 61 20 73 |.of byte|s at a s|
|000000f0| 70 65 63 69 66 69 65 64 | 20 61 64 64 72 65 73 73 |pecified| address|
|00000100| 29 20 61 6e 64 20 61 20 | 73 74 72 69 6e 67 20 6f |) and a |string o|
|00000110| 66 20 68 65 78 61 64 65 | 63 69 6d 61 6c 20 64 69 |f hexade|cimal di|
|00000120| 67 69 74 73 2e 20 54 77 | 6f 20 68 65 78 0d 64 69 |gits. Tw|o hex.di|
|00000130| 67 69 74 73 20 72 65 70 | 72 65 73 65 6e 74 20 6f |gits rep|resent o|
|00000140| 6e 65 20 62 69 6e 61 72 | 79 20 62 79 74 65 2e 0d |ne binar|y byte..|
|00000150| 0d 50 4f 52 54 41 42 49 | 4c 49 54 59 3a 20 53 74 |.PORTABI|LITY: St|
|00000160| 61 6e 64 61 72 64 20 43 | 2e 0d 0d 48 49 53 54 4f |andard C|...HISTO|
|00000170| 52 59 3a 0d 35 2f 32 37 | 2f 39 33 20 64 67 70 20 |RY:.5/27|/93 dgp |
|00000180| 77 72 6f 74 65 20 69 74 | 2c 20 70 61 72 74 6c 79 |wrote it|, partly|
|00000190| 20 62 61 73 65 64 20 6f | 6e 20 63 6f 64 65 20 49 | based o|n code I|
|000001a0| 27 64 20 70 72 65 76 69 | 6f 75 73 6c 79 20 77 72 |'d previ|ously wr|
|000001b0| 69 74 74 65 6e 20 66 6f | 72 20 0d 09 09 09 50 69 |itten fo|r ....Pi|
|000001c0| 78 4d 61 70 54 6f 50 6f | 73 74 53 63 72 69 70 74 |xMapToPo|stScript|
|000001d0| 2e 63 20 0d 36 2f 31 35 | 2f 39 33 09 64 67 70 20 |.c .6/15|/93.dgp |
|000001e0| 6d 69 6e 6f 72 20 65 64 | 69 74 69 6e 67 0d 2a 2f |minor ed|iting.*/|
|000001f0| 0d 23 69 6e 63 6c 75 64 | 65 20 22 56 69 64 65 6f |.#includ|e "Video|
|00000200| 54 6f 6f 6c 62 6f 78 2e | 68 22 0d 0d 69 6e 74 20 |Toolbox.|h"..int |
|00000210| 48 65 78 54 6f 42 69 6e | 61 72 79 28 63 68 61 72 |HexToBin|ary(char|
|00000220| 20 2a 73 74 72 69 6e 67 | 2c 76 6f 69 64 20 2a 70 | *string|,void *p|
|00000230| 74 72 29 0d 2f 2a 20 46 | 61 73 74 20 74 72 61 6e |tr)./* F|ast tran|
|00000240| 73 6c 61 74 69 6f 6e 20 | 6f 66 20 61 20 68 65 78 |slation |of a hex|
|00000250| 20 73 74 72 69 6e 67 20 | 6f 66 20 61 72 62 69 74 | string |of arbit|
|00000260| 72 61 72 79 20 6c 65 6e | 67 74 68 2e 20 2a 2f 0d |rary len|gth. */.|
|00000270| 7b 0d 09 72 65 67 69 73 | 74 65 72 20 75 6e 73 69 |{..regis|ter unsi|
|00000280| 67 6e 65 64 20 63 68 61 | 72 20 2a 62 79 74 65 2c |gned cha|r *byte,|
|00000290| 63 2c 64 65 68 65 78 5b | 32 35 36 5d 3b 0d 09 72 |c,dehex[|256];..r|
|000002a0| 65 67 69 73 74 65 72 20 | 75 6e 73 69 67 6e 65 64 |egister |unsigned|
|000002b0| 20 6c 6f 6e 67 20 69 3b | 0d 09 73 69 7a 65 5f 74 | long i;|..size_t|
|000002c0| 20 64 69 67 69 74 73 3b | 0d 0d 09 66 6f 72 28 69 | digits;|...for(i|
|000002d0| 3d 30 3b 69 3c 73 69 7a | 65 6f 66 28 64 65 68 65 |=0;i<siz|eof(dehe|
|000002e0| 78 29 3b 69 2b 2b 29 64 | 65 68 65 78 5b 69 5d 3d |x);i++)d|ehex[i]=|
|000002f0| 32 35 35 3b 0d 09 66 6f | 72 28 69 3d 30 3b 69 3c |255;..fo|r(i=0;i<|
|00000300| 31 30 3b 69 2b 2b 29 64 | 65 68 65 78 5b 69 2b 27 |10;i++)d|ehex[i+'|
|00000310| 30 27 5d 3d 69 3b 0d 09 | 66 6f 72 28 69 3d 30 3b |0']=i;..|for(i=0;|
|00000320| 69 3c 36 3b 69 2b 2b 29 | 64 65 68 65 78 5b 69 2b |i<6;i++)|dehex[i+|
|00000330| 27 61 27 5d 3d 64 65 68 | 65 78 5b 69 2b 27 41 27 |'a']=deh|ex[i+'A'|
|00000340| 5d 3d 69 2b 31 30 3b 0d | 09 64 69 67 69 74 73 3d |]=i+10;.|.digits=|
|00000350| 73 74 72 6c 65 6e 28 73 | 74 72 69 6e 67 29 3b 0d |strlen(s|tring);.|
|00000360| 09 62 79 74 65 3d 28 75 | 6e 73 69 67 6e 65 64 20 |.byte=(u|nsigned |
|00000370| 63 68 61 72 20 2a 29 73 | 74 72 69 6e 67 3b 0d 09 |char *)s|tring;..|
|00000380| 66 6f 72 28 69 3d 30 3b | 69 3c 64 69 67 69 74 73 |for(i=0;|i<digits|
|00000390| 3b 69 2b 2b 29 69 66 28 | 64 65 68 65 78 5b 2a 62 |;i++)if(|dehex[*b|
|000003a0| 79 74 65 2b 2b 5d 3d 3d | 32 35 35 29 72 65 74 75 |yte++]==|255)retu|
|000003b0| 72 6e 20 31 3b 09 2f 2a | 20 20 49 6c 6c 65 67 61 |rn 1;./*| Illega|
|000003c0| 6c 20 63 68 61 72 61 63 | 74 65 72 20 2a 2f 0d 09 |l charac|ter */..|
|000003d0| 62 79 74 65 3d 28 75 6e | 73 69 67 6e 65 64 20 63 |byte=(un|signed c|
|000003e0| 68 61 72 20 2a 29 70 74 | 72 3b 0d 09 66 6f 72 28 |har *)pt|r;..for(|
|000003f0| 69 3d 64 69 67 69 74 73 | 2f 32 3b 69 3e 30 3b 69 |i=digits|/2;i>0;i|
|00000400| 2d 2d 29 7b 0d 09 09 63 | 3d 64 65 68 65 78 5b 2a |--){...c|=dehex[*|
|00000410| 73 74 72 69 6e 67 2b 2b | 5d 3b 0d 09 09 63 3c 3c |string++|];...c<<|
|00000420| 3d 34 3b 0d 09 09 63 2b | 3d 64 65 68 65 78 5b 2a |=4;...c+|=dehex[*|
|00000430| 73 74 72 69 6e 67 2b 2b | 5d 3b 0d 09 09 2a 62 79 |string++|];...*by|
|00000440| 74 65 2b 2b 20 3d 63 3b | 0d 09 7d 0d 09 72 65 74 |te++ =c;|..}..ret|
|00000450| 75 72 6e 20 30 3b 09 2f | 2a 20 20 53 75 63 63 65 |urn 0;./|* Succe|
|00000460| 73 73 20 2a 2f 0d 7d 0d | 0d 63 68 61 72 20 2a 42 |ss */.}.|.char *B|
|00000470| 69 6e 61 72 79 54 6f 48 | 65 78 28 73 69 7a 65 5f |inaryToH|ex(size_|
|00000480| 74 20 6e 2c 76 6f 69 64 | 20 2a 70 74 72 2c 63 68 |t n,void| *ptr,ch|
|00000490| 61 72 20 2a 73 74 72 69 | 6e 67 29 0d 2f 2a 20 20 |ar *stri|ng)./* |
|000004a0| 46 61 73 74 20 65 6e 63 | 6f 64 69 6e 67 20 6f 66 |Fast enc|oding of|
|000004b0| 20 61 20 73 70 65 63 69 | 66 69 65 64 20 6e 75 6d | a speci|fied num|
|000004c0| 62 65 72 20 6f 66 20 62 | 79 74 65 73 20 61 73 20 |ber of b|ytes as |
|000004d0| 61 20 68 65 78 20 73 74 | 72 69 6e 67 2e 20 2a 2f |a hex st|ring. */|
|000004e0| 0d 2f 2a 20 20 22 73 74 | 72 69 6e 67 22 2c 20 69 |./* "st|ring", i|
|000004f0| 66 20 6e 6f 74 20 4e 55 | 4c 4c 2c 20 6d 75 73 74 |f not NU|LL, must|
|00000500| 20 62 65 20 61 62 6c 65 | 20 74 6f 20 68 6f 6c 64 | be able| to hold|
|00000510| 20 61 74 20 6c 65 61 73 | 74 20 32 2a 6e 2b 31 20 | at leas|t 2*n+1 |
|00000520| 62 79 74 65 73 2e 20 2a | 2f 0d 7b 0d 09 72 65 67 |bytes. *|/.{..reg|
|00000530| 69 73 74 65 72 20 6c 6f | 6e 67 20 69 2c 6a 3b 0d |ister lo|ng i,j;.|
|00000540| 09 72 65 67 69 73 74 65 | 72 20 75 6e 73 69 67 6e |.registe|r unsign|
|00000550| 65 64 20 73 68 6f 72 74 | 20 2a 77 6f 72 64 2c 68 |ed short| *word,h|
|00000560| 65 78 5b 32 35 36 5d 3b | 0d 09 72 65 67 69 73 74 |ex[256];|..regist|
|00000570| 65 72 20 75 6e 73 69 67 | 6e 65 64 20 63 68 61 72 |er unsig|ned char|
|00000580| 20 2a 62 79 74 65 3b 0d | 09 73 74 61 74 69 63 20 | *byte;.|.static |
|00000590| 63 6f 6e 73 74 20 75 6e | 73 69 67 6e 65 64 20 63 |const un|signed c|
|000005a0| 68 61 72 20 63 5b 5d 3d | 22 30 31 32 33 34 35 36 |har c[]=|"0123456|
|000005b0| 37 38 39 61 62 63 64 65 | 66 22 3b 0d 09 6c 6f 6e |789abcde|f";..lon|
|000005c0| 67 20 64 69 67 69 74 73 | 3b 0d 09 73 68 6f 72 74 |g digits|;..short|
|000005d0| 20 6f 64 64 41 64 64 72 | 65 73 73 3b 0d 0d 09 61 | oddAddr|ess;...a|
|000005e0| 73 73 65 72 74 28 73 69 | 7a 65 6f 66 28 2a 62 79 |ssert(si|zeof(*by|
|000005f0| 74 65 29 3d 3d 31 29 3b | 09 2f 2a 20 20 72 65 71 |te)==1);|./* req|
|00000600| 75 69 72 65 64 20 62 79 | 20 6f 75 72 20 61 6c 67 |uired by| our alg|
|00000610| 6f 72 69 74 68 6d 20 2a | 2f 0d 09 61 73 73 65 72 |orithm *|/..asser|
|00000620| 74 28 73 69 7a 65 6f 66 | 28 2a 77 6f 72 64 29 3d |t(sizeof|(*word)=|
|00000630| 3d 32 29 3b 09 2f 2a 20 | 20 72 65 71 75 69 72 65 |=2);./* | require|
|00000640| 64 20 62 79 20 6f 75 72 | 20 61 6c 67 6f 72 69 74 |d by our| algorit|
|00000650| 68 6d 20 2a 2f 0d 09 66 | 6f 72 28 6a 3d 30 3b 6a |hm */..f|or(j=0;j|
|00000660| 3c 31 36 3b 6a 2b 2b 29 | 66 6f 72 28 69 3d 30 3b |<16;j++)|for(i=0;|
|00000670| 69 3c 31 36 3b 69 2b 2b | 29 68 65 78 5b 28 6a 3c |i<16;i++|)hex[(j<|
|00000680| 3c 34 29 2b 69 5d 3d 28 | 63 5b 6a 5d 3c 3c 38 29 |<4)+i]=(|c[j]<<8)|
|00000690| 2b 63 5b 69 5d 3b 0d 09 | 64 69 67 69 74 73 3d 32 |+c[i];..|digits=2|
|000006a0| 2a 6e 3b 0d 09 69 66 28 | 73 74 72 69 6e 67 3d 3d |*n;..if(|string==|
|000006b0| 4e 55 4c 4c 29 7b 0d 09 | 09 73 74 72 69 6e 67 3d |NULL){..|.string=|
|000006c0| 28 63 68 61 72 20 2a 29 | 6d 61 6c 6c 6f 63 28 64 |(char *)|malloc(d|
|000006d0| 69 67 69 74 73 2b 31 29 | 3b 0d 09 09 69 66 28 73 |igits+1)|;...if(s|
|000006e0| 74 72 69 6e 67 3d 3d 4e | 55 4c 4c 29 72 65 74 75 |tring==N|ULL)retu|
|000006f0| 72 6e 20 4e 55 4c 4c 3b | 0d 09 7d 0d 09 6f 64 64 |rn NULL;|..}..odd|
|00000700| 41 64 64 72 65 73 73 3d | 28 75 6e 73 69 67 6e 65 |Address=|(unsigne|
|00000710| 64 20 6c 6f 6e 67 29 73 | 74 72 69 6e 67 25 32 3b |d long)s|tring%2;|
|00000720| 0d 09 69 66 28 6f 64 64 | 41 64 64 72 65 73 73 29 |..if(odd|Address)|
|00000730| 73 74 72 69 6e 67 2b 2b | 3b 0d 09 77 6f 72 64 3d |string++|;..word=|
|00000740| 28 75 6e 73 69 67 6e 65 | 64 20 73 68 6f 72 74 20 |(unsigne|d short |
|00000750| 2a 29 73 74 72 69 6e 67 | 3b 0d 09 62 79 74 65 3d |*)string|;..byte=|
|00000760| 28 75 6e 73 69 67 6e 65 | 64 20 63 68 61 72 20 2a |(unsigne|d char *|
|00000770| 29 70 74 72 3b 0d 09 66 | 6f 72 28 69 3d 6e 3b 69 |)ptr;..f|or(i=n;i|
|00000780| 3e 30 3b 69 2d 2d 29 2a | 77 6f 72 64 2b 2b 20 3d |>0;i--)*|word++ =|
|00000790| 20 68 65 78 5b 2a 62 79 | 74 65 2b 2b 5d 3b 0d 09 | hex[*by|te++];..|
|000007a0| 69 66 28 6f 64 64 41 64 | 64 72 65 73 73 29 7b 0d |if(oddAd|dress){.|
|000007b0| 09 09 2f 2a 20 6d 6f 76 | 65 20 62 61 63 6b 20 2a |../* mov|e back *|
|000007c0| 2f 0d 09 09 73 74 72 69 | 6e 67 2d 2d 3b 0d 09 09 |/...stri|ng--;...|
|000007d0| 6d 65 6d 6d 6f 76 65 28 | 73 74 72 69 6e 67 2c 73 |memmove(|string,s|
|000007e0| 74 72 69 6e 67 2b 31 2c | 64 69 67 69 74 73 29 3b |tring+1,|digits);|
|000007f0| 0d 09 7d 0d 09 73 74 72 | 69 6e 67 5b 64 69 67 69 |..}..str|ing[digi|
|00000800| 74 73 5d 3d 30 3b 0d 09 | 72 65 74 75 72 6e 20 73 |ts]=0;..|return s|
|00000810| 74 72 69 6e 67 3b 0d 7d | 0d 00 00 00 00 00 00 00 |tring;.}|........|
|00000820| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000830| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000840| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000850| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000860| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000870| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000880| 00 00 01 00 00 00 01 54 | 00 00 00 54 00 00 00 46 |.......T|...T...F|
|00000890| 63 61 6c 74 69 6d 65 28 | 26 41 4e 53 49 54 69 6d |caltime(|&ANSITim|
|000008a0| 65 29 29 3b 0d 09 66 70 | 72 69 6e 74 66 28 66 69 |e));..fp|rintf(fi|
|000008b0| 0d 48 65 78 54 6f 42 69 | 6e 61 72 79 2e 63 02 00 |.HexToBi|nary.c..|
|000008c0| 00 00 54 45 58 54 43 57 | 49 45 01 00 00 50 02 40 |..TEXTCW|IE...P.@|
|000008d0| 00 00 54 45 58 54 43 57 | 49 45 01 00 00 50 02 40 |..TEXTCW|IE...P.@|
|000008e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000008f0| 00 00 a8 29 ed 68 00 00 | 07 99 00 00 01 9a 69 66 |...).h..|......if|
|00000900| 79 41 70 70 6c 69 63 61 | 74 69 6f 6e 28 29 29 3b |yApplica|tion());|
|00000910| 0d 09 66 70 72 69 6e 74 | 66 28 66 69 6c 65 2c 0d |..fprint|f(file,.|
|00000920| 09 09 22 25 25 25 25 46 | 6f 72 3a 25 73 5c 6e 22 |.."%%%%F|or:%s\n"|
|00000930| 2c 49 64 65 6e 74 69 66 | 79 4f 77 6e 65 72 28 29 |,Identif|yOwner()|
|00000940| 29 3b 0d 09 66 70 72 69 | 6e 74 66 28 66 69 6c 65 |);..fpri|ntf(file|
|00000950| 2c 0d 09 09 22 25 25 25 | 25 54 69 74 6c 65 3a 25 |,..."%%%|%Title:%|
|00000960| 73 5c 6e 22 2c 66 69 6c | 65 6e 61 6d 65 29 3b 0d |s\n",fil|ename);.|
|00000970| 09 66 70 72 69 6e 74 66 | 28 66 69 6c 65 2c 0d 09 |.fprintf|(file,..|
|00000980| 00 00 00 48 00 09 4d 6f | 6e 61 63 6f 00 00 00 00 |...H..Mo|naco....|
|00000990| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000009a0| 00 00 00 00 00 00 00 03 | 00 04 00 3d 00 0a 01 d7 |........|...=....|
|000009b0| 02 80 00 3d 00 0a 01 d7 | 02 80 ac b5 e7 d4 00 00 |...=....|........|
|000009c0| 01 8b 00 00 01 8b 00 00 | 00 00 01 00 00 00 00 04 |........|........|
|000009d0| 00 01 00 01 00 00 01 00 | 00 00 01 54 00 00 00 54 |........|...T...T|
|000009e0| 00 00 00 46 01 cd a5 18 | 35 fc 00 00 00 1c 00 46 |...F....|5......F|
|000009f0| 00 01 4d 50 53 52 00 00 | 00 12 4d 57 42 42 00 00 |..MPSR..|..MWBB..|
|00000a00| 00 1e 03 ed ff ff 00 00 | 00 00 00 00 00 00 03 f0 |........|........|
|00000a10| ff ff 00 00 00 4c 00 00 | 00 00 00 00 00 00 00 00 |.....L..|........|
|00000a20| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a30| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a40| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a50| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a60| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a70| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
+--------+-------------------------+-------------------------+--------+--------+